<?php

namespace App\Http\Controllers\Wechat\User;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repos\UserGroupbuyRepo;
use App\Http\Requests\Api\UserGroupbuyRequest;
use Carbon\Carbon;

class UserGroupbuyController extends Controller
{
     public function index(CartRequest $request)
    {
    
    	$rs['status'] = false;
    	$where['user_id'] = $request->user_id;
    	$list = UserGroupbuyRepo::getPages($where,$num=10);
    	if($list) {
    		$rs['status'] = true;
    		$rs['data'] = $list;
    		return response()->json($rs);
    	}
    	return response()->json($rs);
    }

    // 发起拼团
    public function create(UserGroupbuyRequest $request)
    {
        $rs['status'] = false;
        $data = $request->pure();
        $data['status'] = 1;

        $flag = UserGroupbuyRepo::create($data);
        if($flag['status']==true) {
            $rs['status'] = true;
            return response()->json($rs);
        }
        $rs['msg'] = $flag['msg'];
        return response()->json($rs);
    }  

    // // 跟随组团
    // public function follow()
    // {
    // 	$rs['status'] = false;
    //     $data = $request->pure();        
    //     $flag = UserGroupbuyRepo::follow($data);
    //     if($flag) {
    //         $rs['status'] = true;
    //         return response()->json($rs);
    //     }
    //     return response()->json($rs);
    //} 
}
